// pages/order-list/orderlist.js
const { httpGet } = require('../../utils/util.js')
const util = require('../../utils/util.js')
const app = getApp() // 获取app.js

Page({
  data: {
    api: app.globalData.api,
    orderList: [],  // 用于存储所有订单的数组
  },
  onLoad: function (options) {
    util.httpGet('/wx/order?uid=0', resp => {
      // util.alert(resp.order)
      // this.data.uid = wx.getStorageSync('uid') // 获取缓存中的用户id                             
      this.data.orderList = resp.order
      this.setData(this.data)
    },
  )},
  // 删除订单
  deleteOrder: function(e){
    // util.alert(e.currentTarget.dataset.id)
    wx.showModal({
      title: '提示',
      content: '确定要删除该订单吗？',
      success: function (res) {
        if (res.confirm) {
          util.httpGet('/wx/deleteOrder?id='+e.currentTarget.dataset.id, resp=>{})
        } else {
          console.log('用户点击取消')
        }
      }
    })
  },
  toIndexPage: function() {
    wx.switchTab({
      url: "/pages/index/index"
    });
  }
})